package com.sinosoft.tcmemr.webservice.client;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.sinosoft.tcmemr.webservice.TCMEMRWebService;

public class TCMEMRWsClient {
	/**
	 * 请求Spring整合CXF的WebService客户端
	 * 
	 * @author
	 * 
	 */
	////@Test
	public void clientFirst() {
		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		factory.setServiceClass(TCMEMRWebService.class);
		factory.setAddress("http://localhost:8080/TCMEMR/webService/tcmemrWebService");

		TCMEMRWebService tcmemrservice = (TCMEMRWebService) factory.create();

		System.out.println("#############Client getUserByName##############");
		String myrequest = "<DoctorUser><aid>TCMEMR</aid><name>张三</name></DoctorUser>";
		System.out.println(tcmemrservice.sayHello(myrequest));
		System.out.println(tcmemrservice.TCMEMR_addDoctorUsers(myrequest));

	}

	public static void clientToXML() {
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"applicationContext.xml");
		try {
		TCMEMRWebService tcmemrservice = ctx.getBean("tcmemrWsClient",
				TCMEMRWebService.class);

		System.out.println("#############Client getUserByName##############");
		String myrequest = "<DoctorUser><aid>TCMEMR</aid><name>张三</name></DoctorUser>";
		System.out.println(tcmemrservice.TCMEMR_addDoctorUsers(myrequest));
		} finally {
			if ( ctx != null ){ 
				((ClassPathXmlApplicationContext)ctx).close();
				ctx = null;
			}
		}
	}

	public static void main(String[] args) {
		///clientToXML();
		///clientFirst();
	}

}
